#include "Obstacle.h"

CObstacle::CObstacle()
{
	mObjectClassification = ObjectClassification_Obstacle;
	b2BodyDef groundBodyDef;
	groundBodyDef.position.Set(0, 0);

	mBody = gBoxWorld->CreateBody(&groundBodyDef); 
	this->autorelease();
}
CObstacle::~CObstacle()
{
	gBoxWorld->DestroyBody(mBody);
}
void CObstacle::Load(CCDictionary* ObsDic)
{
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();

	CCArray *_array = (CCArray*)(ObsDic->objectForKey("linePhy"));
	b2EdgeShape groundBoxEdge;
	int count = _array->count();
	for (int i=0; i<count; i++) {
		CCString *tmpStr = (CCString*)_array->objectAtIndex(i);
		CCRect rect =  CCRectFromString(tmpStr->getCString());
		groundBoxEdge.Set(b2Vec2( (rect.origin.x * winSize.width)/kPTM_RATIO, ((1.0-rect.origin.y)*winSize.height)/kPTM_RATIO), 
			b2Vec2( (rect.size.width * winSize.width)/kPTM_RATIO, ((1.0-rect.size.height)*winSize.height)/kPTM_RATIO));
		mBody->CreateFixture(&groundBoxEdge, 0);
	}
}